<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@page import="com.yy.base.util.UserUtil"%>
<%
if (session.getAttribute(UserUtil.USERSESSION) == null) {
	response.sendRedirect(request.getContextPath());
	return;
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<title>数据采集</title>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
	<script src="../../script/mes-import.js"></script>
	<script src="js/orderInfo.js"></script>
</head>
<body style="padding: 10px;" id="manuDataCollection">
<form class="layui-form" action="" lay-filter="myForm">
	<div class="layui-form-item">
		<div class="layui-input-inline">
			<label class="layui-form-label" style="text-align: right;">RFID：</label>
			<div class="layui-input-block">
				<input type="text" name="code" id="code" lay-verify="code" autocomplete="off" placeholder="请扫描RFID" class="layui-input">
				<img src="../../script/imgs/scan.png" scanButton onclick="scan('code')"/>
			</div>
		</div>
		<div class="layui-input-inline" id="userCodePanel" style="display: none;">
			<label class="layui-form-label" style="text-align: right;">工号：</label>
			<div class="layui-input-block">
				<input type="text" name="userCode" id="userCode" lay-verify="userCode" autocomplete="off" placeholder="请扫描员工工号" class="layui-input">
				<img src="../../script/imgs/scan.png" scanButton onclick="scan('userCode')"/>
			</div>
		</div>
	</div>
	<div class="layui-form-item" id="orderInfoPanel" style="display: none;">
        <label class="layui-form-label"></label>
        <div class="layui-input-block" id="orderInfo">工单信息</div>
    </div>
    <div class="layui-form-item" style="display: none;">
		<div class="layui-input-inline">
			<label class="layui-form-label">当前工序：</label>
			<div class="layui-input-block">
				<select name="processId" id="processId" lay-verify="processId" style="max-width: 400px;">
					<option value="">--请选择--</option>
					<option v-for="p in processList" value="{{p.emes_process_id}}">{{p.name}}</option>
				</select>
			</div>
		</div>
    </div>
	<div class="row" id="facInputPanel" style="display: none;">
		<div class="layui-form-item">
			<div class="layui-input-inline">
				<label class="layui-form-label">设备编码:</label>
				<div class="layui-input-block">
					<input id="facCode" name="facCode" placeholder="请扫描设备编码" autocomplete="off" class="layui-input"/>
					<img src="../../script/imgs/scan.png" scanButton onclick="scan('facCode')"  />
				</div>
			</div>
			<div class="layui-input-inline" id="facInfoPanel">
				<label class="layui-form-label"></label>
				<div class="layui-input-block" id="facInfo"></div>
			</div>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-inline">
			<label class="layui-form-label">备注：</label>
			<div class="layui-input-block">
				<textarea id="description" style="height: 40px;" class="layui-textarea" placeholder="此处填写备注信息"></textarea>
			</div>
		</div>
	</div>
	<div class="layui-form-item" id="manuBatchBtn">
		<div class="layui-input-block">
			<button class="layui-btn" type="button" onclick="submitData()">报工</button>
			<button class="layui-btn" type="button" onclick="refresh()">刷新</button>
			<button class="layui-btn" type="button" onclick="rework()" v-if="showRework">{{reworkText}}</button>
			<button class="layui-btn" type="button" v-for="btnItem in Dc_Btn_List" v-if="!(btnItem.IS_HIDE_DC_PAGE == 'Y')"
					onclick="manuDataDc('{{btnItem.EMES_DC_INPUT_DATA_ID}}','{{btnItem.TYPE}}','{{btnItem.OPEN_URL}}')">{{btnItem.NAME}}</button>
		</div>
	</div>
</form>
<form class="layui-form" action="" lay-filter="dataForm">
	<div class="tabs ipad">
		<ul role="tablist">
			<li role="tab" v-for="btnItem in Dc_Btn_List"
				v-if="!(btnItem.IS_HIDE_DC_PAGE == 'Y') && btnItem.TYPE == 'DC'"
				aria-controls="#tab{{btnItem.id}}"
				id="li{{btnItem.id}}">{{btnItem.name}}列表</li>
		</ul>
		<div  v-for="item in hisDataList"  id="tab{{item.PAGEID}}" role="tabpanel">
			<div style="position: absolute;right: 15px;top:-6px;">
				<button class="layui-btn" onclick="saveDCData('{{item.PAGEID}}')">保存</button>
			</div>
			<div id="historyData{{$index}}">
				<table class="responsive" data-max="15">
					<thead>
					<tr>
						<th>序列号</th>
						<th>操作人</th>
						<th>操作时间</th>
						<th v-for="columnItem in item.COLUMN" v-if="!(columnItem.IS_SHOW == 'N')">
								{{columnItem.NAME}}{{columnItem.CUNAME?'(':''}}{{columnItem.CUNAME}}{{columnItem.CUNAME?')':''}}
						</th>
						<th>操作</th>
					</tr>
					</thead>
					<tbody>
					<tr v-for="trItem in item.DATA">
						<td>{{$index+1}}</td>
						<td>{{trItem['USERNAME']}}</td>
						<td>{{trItem['CREATED']}}</td>
						<td v-for="tdItem in item.COLUMN" v-if="!(tdItem.IS_SHOW == 'N')">
							<input v-model="trItem[tdItem.SAVE_COLUMN]" id="{{trItem['EMESO_MANU_PROCESS_DATA_ID']}}{{tdItem.CODE}}"/>
						</td>
						<td><a href="javascript:void(0);" onclick="delManuData(\'{{trItem['EMESO_MANU_PROCESS_DATA_ID']}}\')">删除</a></td>
					</tr>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</form>
<script>
var vm = new Vue({
	el:'#manuDataCollection',
	data:{
		hisDataList: [],
		Dc_Btn_List: [],
		processList: [],
        showRework: false,
		showAddMatBtn: false,	//显示加料按钮
		reworkText: "返工"		//返工按钮文本
	},
	methods:{
		isEmpty:function(obj){//判断对象是否为空
			if(typeof obj == "undefined" || obj == null || obj == ""){
				return true;
			}else{
				return false;
			}
		}
	},
	watch:{
		hisDataList:{
			handler: function(curVal,oldVal){
				var _self = this;
				$.each(curVal,function(index,item){
					var map = {};
					var keySet = [];
					var calFormula = {};
					$.each(item.COLUMN,function(j,subItem){
						map[subItem.NAME] = subItem.SAVE_COLUMN;
						map["前_"+subItem.NAME] = "PRE_"+subItem.SAVE_COLUMN;//此项目前一行的键值对
						keySet.push(subItem.NAME);
						if(subItem.FORMULA && subItem.FORMULA !== ""){
							calFormula[subItem.SAVE_COLUMN] = subItem.FORMULA;
						}
					});
					var reg = null;
					$.each(item.DATA,function(i,v){
						$.each(calFormula,function(k,fItem){
							var no_exec = false;//判断是否执行计算公式
							$.each(keySet,function(x,keyName){
								var reg = new RegExp("前_"+keyName , "g");
								if(reg.test(fItem)){
									fItem = fItem.replace(reg,v[map["前_"+keyName]]);
									no_exec = no_exec || _self.isEmpty(v[map["前_"+keyName]]);
								}
								reg = new RegExp(keyName , "g");
								if(reg.test(fItem)){
									fItem = fItem.replace(reg,v[map[keyName]]);
									no_exec = no_exec || _self.isEmpty(v[map[keyName]]);
								}
							});
							var reg = new RegExp("当前时间" , "g");
							if(reg.test(fItem)){
								fItem = fItem.replace(new RegExp("当前时间" , "g"),v["TIMESTAMP"]);
								no_exec = no_exec || _self.isEmpty(v["TIMESTAMP"]);
							}
							reg = new RegExp("上一时间" , "g");
							if(reg.test(fItem)){
								fItem = fItem.replace(new RegExp("上一时间" , "g"),v["PRE_TIMESTAMP"]);
								no_exec = no_exec || _self.isEmpty(v["PRE_TIMESTAMP"]);
							}

							var reg = new RegExp("当前分钟" , "g");
							if(reg.test(fItem)){
								fItem = fItem.replace(new RegExp("当前分钟" , "g"),v["MINU"]);
								no_exec = no_exec || _self.isEmpty(v["MINU"]);
							}
							reg = new RegExp("上一分钟" , "g");
							if(reg.test(fItem)){
								fItem = fItem.replace(new RegExp("上一分钟" , "g"),v["PRE_MINU"]);
								no_exec = no_exec || _self.isEmpty(v["PRE_MINU"]);
							}
							if(!no_exec){//为true才执行计算公式
								try {
									var tmpValue = eval(fItem).toFixed(2);
									if(isNaN(tmpValue) || !isFinite(tmpValue)){
										v[k] = '';
									}else{
										v[k] = tmpValue;
									}
								} catch (e) {
								}
							}
						});
					});
				});
			},
			deep:true
		}
	}
});
</script>
</body>
</html>